using System;
using System.Linq;
class ProgramReaction : ProfileReaction
{
    public ProgramReaction(string page, string profile, int index, FreeTime free_time)
        : base(page, profile) {
        this.index = index;
        this.free_time = free_time;
    }

    readonly int index;
    readonly FreeTime free_time;

    public override string GetContent() {

        var ret = base.GetContent();

        ret = ret.Replace("#{INDEX}", index + "");

        var program = Fitness.GenerateProgram(Helpers.GetUserInfo(Profile), index, free_time);

        // todo: generate html
        var exercises = string.Join("\n", program.Exercises.OrderBy(_e => _e.Time).Select(_e => string.Format("{0} {1} {2} {3}", _e.Time, _e.Units, _e.ExerciseInfo.Unit, _e.ExerciseInfo.Name)));
        var meals = string.Join("\n", program.Eating.OrderBy(_f => _f.Time).Select(_f => string.Format("{0} {1} {2} {3}", _f.Time, _f.Units, _f.FoodInfo.ServingUnit, _f.FoodInfo.Name)));



        ret = ret.Replace("#{EXERCISES}", exercises);
        ret = ret.Replace("#{MEALS}", meals);

        return ret;
    }

}
